/***************************************************************************
 *   Copyright (C) 2007 by saa   *
 *   root@saa   *
 ***************************************************************************/

#ifndef ROUTESERVER_H
#define ROUTESERVER_H

#include <QStringList>
#include <QFlags>

struct RouteServer
{
    RouteServer(const QString & _hostname,
                const QString & _password,
                const QString & _username,
                const QString & _loginPattern,
                const QString & _passwordPattern,
                const QString & _promptPattern) :
            hostname(_hostname),
            password(_password),
            username(_username),
            loginPattern(_loginPattern),
            passwordPattern(_passwordPattern),
            promptPattern(_promptPattern){}
            
    RouteServer() {}
            
    QString hostname;
    QString password;
    QString username;
    QString loginPattern;
    QString passwordPattern;
    QString promptPattern;
};

struct tracerouteNode
{
    tracerouteNode(const unsigned int _ttl,
                   const QString & _hostIP,
                   const QString & _hostName,
                   const QString & _asn,
                   const QString & _tripTime
                   )
    {
        ttl.append(_ttl);
        hostIP.append(_hostIP);
        hostName.append(_hostName);
        asn.append(_asn);
        tripTime.append(_tripTime);
    }

    tracerouteNode() :
            hostIP(""),
            hostName(""),
            asn(""),
            tripTime("")
        {
            ttl.append(0);
        }
    
    void append(const unsigned int _ttl, const QString & _hostIP, const QString & _hostName, const QString & _asn, const QString & _tripTime)
    {
        ttl.append(_ttl);
        hostIP.append(_hostIP);
        hostName.append(_hostName);
        asn.append(_asn);
        tripTime.append(_tripTime);
    }
    
    QList<unsigned int> ttl;
    QStringList hostIP;
    QStringList hostName;
    QStringList asn;
    QStringList tripTime;
};

struct Link
{
        Link(const unsigned int _begin, const unsigned int  _end, const double _averageTime, const int _nodeCount) :
            begin(_begin),
            end(_end),
            averageTime(_averageTime),
            nodeCount(_nodeCount){}

        Link(const unsigned int _begin, const unsigned int  _end, const double _averageTime) :
                    begin(_begin),
            end(_end),
            averageTime(_averageTime),
            nodeCount(1){}
            
        Link(){}

        friend bool operator==(const Link & link1, const Link & link2)
        {
            return link1.begin == link2.begin && link1.end == link2.end;
        }
        
        unsigned int begin;
        unsigned int end;
        double averageTime;
        int nodeCount;
};

class LinkList
{
    QList<Link> linkList;   
    public:    
    void append(const Link & link)
    {
        //TODO check TIME!
        int index = linkList.indexOf(link);
        if(index == -1)
            linkList.append(link);
        else 
            linkList[index].averageTime = (linkList.at(index).averageTime * linkList.at(index).nodeCount + link.averageTime) / ++linkList[index].nodeCount;
    }
    
    const Link at(const int i) const {return linkList.at(i);}
    int size() const {return linkList.size();}
};

class LogFlag
{
    public:
        enum LogLevel
        {
            Common = 0x0002,
            TelnetClient = 0x0020,
            TelnetClient_DEBUG = 0x0040,
            Parser = 0x0200,
            Parser_DEBUG = 0x0400,
            Database = 0x2000,
            Database_DEBUG = 0x4000
        };
        Q_DECLARE_FLAGS(LogLevels, LogLevel)
};

Q_DECLARE_OPERATORS_FOR_FLAGS(LogFlag::LogLevels)

struct LogMessage
{
    LogMessage(const QString & _message, const LogFlag::LogLevels & _logLevel)
    {
        message = _message;
        logLevel = _logLevel;
    }
    
    QString message;
    LogFlag::LogLevels logLevel;
};

#endif
